package com.wgy.designmode.action.chain.handle;

public abstract class AbstractLogger {

    public static final int DEBUG = 1;

    public static final int INFO = 2;

    public static final int WARN = 3;

    public static final int ERROR = 4;

    protected int level;

    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }

    public AbstractLogger(int level) {
        this.level = level;
    }


    public void logMessage(int level, String message){
        if (this.level <= level){
            // 本类可以处理等级大于等于自身的
            write(message);
        }

        if (nextLogger != null){
            // 传递给下一个处理者
            nextLogger.logMessage(level, message);
        }
    }


    protected abstract void write(String message);
}
